package com.liwy3;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Crazy4J
 * @Date: 2023年08月28日
 */
public class Main {

    static String domain = "https://www.114yygh.com/mobile";
    static String hospitalList = "/hospital/list";
    static String hospitalDetail = "/hospital/detail";
    static String patientList = "/patient/list";
    static String orderCheck = "/order/save/check";
    static String deptList = "/department/hos/list";
    static String productDetail = "/product/detail";
    static String verifyCode = "/common/verify-code/send";
    static String orderSave = "/order/save";
    static String orderConfirm = "/product/confirm";
    static String cookie = "imed_session=F2iTmNCrxjMKG9RvjDXyBeTIWDckPJ0V_5647181; imed_session=F2iTmNCrxjMKG9RvjDXyBeTIWDckPJ0V_5647181; secure-key=43b81d7e-50fa-4809-adf1-049d21c32867; imed_session=F2iTmNCrxjMKG9RvjDXyBeTIWDckPJ0V_5647181; agent_login_img_code=de023fed24c0457fb873ee82e4262583; cmi-user-ticket=S6-N2KokG6j0w9AeJhFi0Vy96HVl9C7ErWiJFw..; imed_session_tm=1694155254908";
    static YQHttp.Request request = YQHttp.newRequest();

    static {
        request = addHeader(request);
//        name=就诊人姓名
//        keyword=医院关键词
//        department=科室关键词
//        autoDelay=轮询间隔秒数（默认10秒）
//        loop=是否自动查询（0否 其他是）
//        deadline=期望最晚挂号时间（格式 yyyy-MM-dd，如 2000-01-01）
//        date=要挂号的指定日期（格式 yyyy-MM-dd，如 2000-01-01）
//        dutyTime=预约的时段（格式 hhmm-hhmm，如 0900-0930）
//        doctorName=指定要预约医生的姓名
//        cookie=114公众号中使用的cookie，可以通过抓包方式获取
    }

    public static void main(String[] args) {
//        System.out.println(getHospitalList());
//        System.out.println(getHospitalDetail());
//        System.out.println(getPatientList());
//        System.out.println(getDeptList());
//        System.out.println(getProductDetail());
        System.out.println(getVerifyCode());
//        System.out.println(checkOrder());
//        System.out.println(confirmOrder());
//        System.out.println(saveOrder());
    }

    /**
     * 获取医院列表
     */
    public static String getHospitalList() {
        Map<Serializable, Object> param = new HashMap<>();
        param.put("keywords", "");
        param.put("sortType", "COMPREHENSIVE");
        param.put("areaId", 0);
        param.put("pageNo", 1);
        param.put("pageSize", 10);
        return request.setUrl(domain + hospitalList).setParameters(param).get().getContent();
    }

    /**
     * 获取医院详情
     */
    public static String getHospitalDetail() {
        Map<Serializable, Object> param = new HashMap<>();
        param.put("hosCode", "143");
        return request.setUrl(domain + hospitalDetail).setParameters(param).get().getContent();
    }

    /**
     * 获取就诊人列表
     */
    public static String getPatientList() {
        return request.setUrl(domain + patientList + "?_time=" + new Date().getTime())
                .post().getContent();
    }

    public static String getDeptList() {
        Map<Serializable, Object> param = new HashMap<>();
        param.put("hosCode", "143");
        return request.setUrl(domain + deptList).setParameters(param).get().getContent();
    }

    public static String getProductDetail() {
        Map<Serializable, Object> param = new HashMap<>();
        param.put("hosCode", "143");
        param.put("firstDeptCode", "69b638bf27b57b6b4400f1e1925f2ace");
        param.put("secondDeptCode", "200001742");
        param.put("target", "2023-09-01");

        return request.setUrl(domain + productDetail).setParameters(param).json().getContent();
    }

    public static String getVerifyCode() {
        //phone是加密的, 抓包中获取
        String param = "&mobile=W3+dLBuWJnUJBjakocUrVOOd64WvH2ldLd4xZc642Wf0ZR5ONvBl02TXuTBFbFwvAGB/cYh6FCPAgn/e9uRph6IcVH7ncdUyKDzZmo4kYPf0wwLmR04fNLST/E4oEKM1WL2zfNxx08VkK0pgmLk5x5/6IoiulePhhiuBBke+L6A=&smsKey=ORDER_CODE&uniqProductKey=ff2fe273b81d63409fb2a1b67938cc873f83bd90";

        return request.setUrl(domain + verifyCode + "?_time=" + new Date().getTime() + param).get().getContent();
    }

    public static String checkOrder() {
        Map<Serializable, Object> param = new HashMap<>();
        param.put("hosCode", "143");
        param.put("firstDeptCode", "69b638bf27b57b6b4400f1e1925f2ace");//getDeptList获取
        param.put("secondDeptCode", "200001742");//getDeptList获取
        param.put("treatmentDay", "2023-09-01");
        param.put("uniqProductKey", "e2aa31dd6ee4cb6d636b6157423d437c101e0ee8");//getProductDetail获取
        param.put("cardType", "IDENTITY_CARD"); //getPatientList获取
        param.put("cardNo", "411321198910253456"); //getPatientList获取
        param.put("smsCode", "846845"); //getVerifyCode获取
        param.put("jytCardId", "");
        param.put("hospitalCardId", "");
        param.put("phone", "");
        param.put("dutyTime", "2023-09-01");


        return request.setUrl(domain + orderCheck).setParameters(param).json().getContent();
    }

    public static String confirmOrder() {
        Map<Serializable, Object> param = new HashMap<>();
        param.put("hosCode", "143");
        param.put("firstDeptCode", "69b638bf27b57b6b4400f1e1925f2ace");//getDeptList获取
        param.put("secondDeptCode", "200001742");//getDeptList获取
        param.put("target", "2023-09-12");
        param.put("uniqProductKey", "e2aa31dd6ee4cb6d636b6157423d437c101e0ee8");//getProductDetail获取
        param.put("dutyTime", "2023-09-12");

        return request.setUrl(domain + orderConfirm).setParameters(param).json().getContent();
    }

    public static String saveOrder() {
        Map<Serializable, Object> param = new HashMap<>();
        param.put("hosCode", "143");
        param.put("firstDeptCode", "69b638bf27b57b6b4400f1e1925f2ace");//getDeptList获取
        param.put("secondDeptCode", "200001742");//getDeptList获取
        param.put("treatmentDay", "2023-09-12");
        param.put("uniqProductKey", "e2aa31dd6ee4cb6d636b6157423d437c101e0ee8");//getProductDetail获取
        param.put("cardType", "IDENTITY_CARD"); //getPatientList获取
        param.put("cardNo", "340223198910260021"); //getPatientList获取
        param.put("smsCode", "846845"); //getVerifyCode获取
        param.put("jytCardId", "");
        param.put("hospitalCardId", "");
        param.put("phone", "16571695843");
        param.put("orderFrom", "HOSP");
        param.put("dutyTime", 0);
        //确认订单返回
        param.put("confirmToken", "OwcIFMqQIg1UERo0ObsmeEU5dl0UDapW9dyBRq0vqhw4uFiwNZqPihogiObuwKY86WmyDPdpsYOlN9J5xE2MSYvRpVjihbnC2EzmIrIrEMk2xlFb7l30yv+WUFIgzBAu");


        return request.setUrl(domain + orderSave).setParameters(param).json().getContent();
    }


    public static YQHttp.Request addHeader(YQHttp.Request request) {
        request.addHeader("Content-Type", "application/json;charset=UTF-8")
                .addHeader("X-Requested-With", "com.tencent.mm")
                .addHeader("Request-Source", "WE_CHAT")
                .addHeader("Referer", "https://www.114yygh.com/wechat/nuclein")
                .addHeader("Cookie", cookie);
        return request;
    }


}
